<?php

namespace Trawind\Basics\Observers;

/**
 * Class TrawindObserver
 * @package Trawind\Basics\Observers
 */
class TrawindObserver
{

    /**
     * @param Illuminate\Database\Eloquent\Model $model
     */
    public function creating($model)
    {
        method_exists($model, 'creatingHandle') and $model->creatingHandle($model);
    }

    /**
     * @param Illuminate\Database\Eloquent\Model $model
     */
    public function created($model)
    {
        method_exists($model, 'createdHandle') and $model->createdHandle($model);
    }

    /**
     * @param Illuminate\Database\Eloquent\Model $model
     */
    public function updating($model)
    {
        method_exists($model, 'updatingHandle') and $model->updatingHandle($model);
    }

    /**
     * @param Illuminate\Database\Eloquent\Model $model
     */
    public function updated($model)
    {
        method_exists($model, 'updatedHandle') and $model->updatedHandle($model);
    }

    /**
     * @param Illuminate\Database\Eloquent\Model $model
     */
    public function saving($model)
    {
        $model->fillOperateUser($model, !is_null($model->created_id));
        method_exists($model, 'savingHandle') and $model->savingHandle($model);
    }

    /**
     * @param Illuminate\Database\Eloquent\Model $model
     */
    public function saved($model)
    {
        method_exists($model, 'savedHandle') and $model->savedHandle($model);
    }

    /**
     * @param Illuminate\Database\Eloquent\Model $model
     */
    public function deleted($model)
    {
        method_exists($model, 'deletedHandle') and $model->deletedHandle($model);
    }
}
